package com.nextgenapp.fbgraph.model.person
{
	import mx.collections.ArrayCollection;

	[Bindable]
	/**
	 * encapsulate ArrayCollection and provide some convenience methods.
	 * @author sol wu
	 */
	public class PersonArrayCollection extends ArrayCollection
	{
		public function PersonArrayCollection(source:Array=null)
		{
			super(source);
		}
		
		/**
		 * @return object representing the user with uid.  null if not found.  
		 */
		public function findPerson(id:String):Person {
			var result:Person = null;
			for each (var obj:Person in this) {
				if (id == obj.id) {
					result = obj;
					break;
				}
			}
			return result;
		}
		
		/**
		 * @return find person by a name.  
		 */
		public function findPersonByName(name:String):Person {
			var result:Person = null;
			for each (var p:Person in this) {
				if (name == p.name) {
					result = p;
					break;
				}
			}
			return result;
		}
		
		/**
		 * return an array of uids (person's id, without the rest of the property)
		 */
		public function getUids():Array {
			var uids:Array = [];
			for each (var p:Person in this) {
				uids.push(p.id);
			}
			return uids;
		}
	}
}